//
//  FourTableViewCell.m
//  Cartoon
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "FourTableViewCell.h"
#import "FourCollectionViewCell.h"
#import "PrefixHeader.pch"
#import "Recommend1.h"

static NSString  *recommendID = @"RMZQCollectionViewCell";

@implementation FourTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(100 * WIDTH, 130 *HEIGHT);
        // 横向滑动
        //  flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        // 每个之间的间距
        
        flowLayout.minimumInteritemSpacing = 5 * WIDTH;
        flowLayout.minimumLineSpacing = 25 * WIDTH;
        self.collectionView =[[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
        [self.contentView addSubview:_collectionView];
        flowLayout.sectionInset = UIEdgeInsetsMake(10 * WIDTH, 15 *HEIGHT , 10* WIDTH, 15  *HEIGHT);
        _collectionView.showsHorizontalScrollIndicator = false;
        _collectionView.backgroundColor =[UIColor clearColor];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        
        self.button = [UIButton buttonWithType:UIButtonTypeSystem];
        
        [self.contentView addSubview:_button];
        
    }
    return self;
    
    
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    _collectionView.frame = CGRectMake(0, 40 *HEIGHT  ,375 * WIDTH , 500 * HEIGHT);
    [_collectionView registerClass:[FourCollectionViewCell class] forCellWithReuseIdentifier:recommendID];
    _titleLabel.frame = CGRectMake(10 * WIDTH, 10 * HEIGHT, 120 * WIDTH, 30 * HEIGHT);
    _titleLabel.font = [UIFont systemFontOfSize:20];
    _titleLabel.textColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];
    _button.frame = CGRectMake(330 * WIDTH, 10 * HEIGHT, 45 * WIDTH, 30 * HEIGHT);
    _button.font = [UIFont systemFontOfSize:20 * WIDTH];
    _button.tintColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count;
    
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FourCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:recommendID forIndexPath:indexPath];
    
    Recommend1 *recommend = [_dataArray objectAtIndex:indexPath.item];
    
    cell.smallTitleLabel.text = recommend.title;
    cell.lastupLabel.text = recommend.lastup;
    
    [cell.QDTJimage sd_setImageWithURL:[NSURL URLWithString:recommend.cover_url]placeholderImage:[UIImage imageNamed:@"5"]];
    
    
    return cell;
    
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake( WIDTH * 165, HEIGHT * 110);
    
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    Recommend1 *recommend =_dataArray[indexPath.row];
    [self.delegate push2Recommend:recommend];
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
